Virtual Memory in Memory Management

Virtual memory allows execution of programs larger than physical memory by loading only required portions into RAM when needed.

Virtual Memory in Memory Management
Virtual memory is a method that allows a computer to run programs even when RAM is limited. It uses secondary storage (like a hard disk) as extra memory. Only the needed part of a program is loaded into RAM while the rest stays on disk.

Why Virtual Memory is Important

Virtual Memory = RAM + Disk (used as extra memory)

Demand Paging

Demand Paging is a memory management technique used in operating systems where pages are loaded into main memory (RAM) only when they are actually required by the CPU. This approach helps in saving memory space and improves system efficiency.
In demand paging, the operating system does not load the complete program into RAM at once. Instead, it loads only those pages that are needed during execution. If a required page is not present in main memory, a page fault occurs.

Demand Paging

Working Process of Demand Paging

Working Process of Demand Paging

Step-by-Step Working of Demand Paging

Step 1 — CPU Requests a Page

The CPU requests a specific page (for example, page P2) for execution. It first checks whether this page is available in the main memory.

Step 2 — Page Table Lookup

The operating system checks the page table entry for page P2. If the page table indicates that P2 is not present in RAM, a page fault is generated.

Step 3 — OS Searches Secondary Memory

After detecting the page fault, the operating system searches for page P2 in secondary memory such as the hard disk, where inactive pages are stored.

Step 4 — Page Transfer to Main Memory

The operating system selects a free frame in main memory (for example, frame F1) and transfers page P2 from disk to this frame.

Step 5 — Page Table Update

Once the page is loaded into RAM, the operating system updates the page table to reflect the new mapping between page P2 and frame F1.

Step 6 — CPU Resumes Execution

After updating the page table, the CPU resumes execution and successfully accesses page P2 from main memory.

Advantages of Demand Paging

Conclusion

Demand paging allows the operating system to manage memory efficiently by loading pages only when they are needed. This technique plays a crucial role in virtual memory systems and improves overall system performance.

Read Related Article: Deadlock in Operating System

What is Page Fault?

A page fault happens when the required page is not found in memory. The system then brings that page from disk into RAM.

Page Fault → Load page from disk → Continue execution

Advantages

Disadvantages

Summary

Swapping

Swapping temporarily moves processes between main memory and secondary storage to free up space for higher-priority processes.

Fragmentation

Memory Protection

Memory protection ensures that processes access only their allocated memory using hardware and software mechanisms.

Advantages of Memory Management

Conclusion

Memory management plays a vital role in the performance and reliability of an operating system. By using techniques such as paging, segmentation, and virtual memory, the OS ensures optimal utilization of limited memory resources.

Visit Our YouTube Channel